package com.beigai.imessage.dao.mapper;

import com.beigai.imessage.dao.po.MessageOfflinePO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.annotations.UpdateProvider;
import org.apache.ibatis.type.JdbcType;

public interface MessageOfflinePOMapper {
    @Delete({
        "delete from message_offline",
        "where id = #{id,jdbcType=BIGINT}"
    })
    int deleteByPrimaryKey(Long id);

    @Insert({
        "insert into message_offline (message_from_code, message_to_code, ",
        "message, message_sort_num, ",
        "message_type, status, ",
        "create_time, update_time)",
        "values (#{messageFromCode,jdbcType=VARCHAR}, #{messageToCode,jdbcType=VARCHAR}, ",
        "#{message,jdbcType=VARCHAR}, #{messageSortNum,jdbcType=INTEGER}, ",
        "#{messageType,jdbcType=INTEGER}, #{status,jdbcType=INTEGER}, ",
        "#{createTime,jdbcType=TIMESTAMP}, #{updateTime,jdbcType=TIMESTAMP})"
    })
    @Options(useGeneratedKeys=true,keyProperty="id")
    int insert(MessageOfflinePO record);

    @InsertProvider(type=MessageOfflinePOSqlProvider.class, method="insertSelective")
    @Options(useGeneratedKeys=true,keyProperty="id")
    int insertSelective(MessageOfflinePO record);

    @Select({
        "select",
        "id, message_from_code, message_to_code, message, message_sort_num, message_type, ",
        "status, create_time, update_time",
        "from message_offline",
        "where id = #{id,jdbcType=BIGINT}"
    })
    @Results({
        @Result(column="id", property="id", jdbcType=JdbcType.BIGINT, id=true),
        @Result(column="message_from_code", property="messageFromCode", jdbcType=JdbcType.VARCHAR),
        @Result(column="message_to_code", property="messageToCode", jdbcType=JdbcType.VARCHAR),
        @Result(column="message", property="message", jdbcType=JdbcType.VARCHAR),
        @Result(column="message_sort_num", property="messageSortNum", jdbcType=JdbcType.INTEGER),
        @Result(column="message_type", property="messageType", jdbcType=JdbcType.INTEGER),
        @Result(column="status", property="status", jdbcType=JdbcType.INTEGER),
        @Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="update_time", property="updateTime", jdbcType=JdbcType.TIMESTAMP)
    })
    MessageOfflinePO selectByPrimaryKey(Long id);

    @UpdateProvider(type=MessageOfflinePOSqlProvider.class, method="updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(MessageOfflinePO record);

    @Update({
        "update message_offline",
        "set message_from_code = #{messageFromCode,jdbcType=VARCHAR},",
          "message_to_code = #{messageToCode,jdbcType=VARCHAR},",
          "message = #{message,jdbcType=VARCHAR},",
          "message_sort_num = #{messageSortNum,jdbcType=INTEGER},",
          "message_type = #{messageType,jdbcType=INTEGER},",
          "status = #{status,jdbcType=INTEGER},",
          "create_time = #{createTime,jdbcType=TIMESTAMP},",
          "update_time = #{updateTime,jdbcType=TIMESTAMP}",
        "where id = #{id,jdbcType=BIGINT}"
    })
    int updateByPrimaryKey(MessageOfflinePO record);
}